package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class HJ12_简单的自动曝光 {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/12.txt"));
        int[] nums = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        findAns(nums);
    }

    static void findAns(int[] nums) {
        int t = Integer.MAX_VALUE;
        int res = 0;
        for (int i = -128; i <= 128; i++) {
            int total = 0;
            for (int j = 0; j < nums.length; j++) {
                int tmp = i + nums[j];
                if (tmp < 0) {
                    tmp = 0;
                } else if (tmp > 255) {
                    tmp = 255;
                }
                total += tmp;
            }
            if (Math.abs(total - 128 * nums.length) < t) {
                t = Math.abs(total - 128 * nums.length);
                res = i;
            }
        }
        System.out.println(res);
    }
}
